/**
 * 
 */
package de.saumya.webfortune.client;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;

public class QuoteButtons extends HorizontalPanel{
  
  private Quote quote;
  
  private final Button next = new Button("next");
  
  private final Button previous = new Button("previous");
  
  private final Button random = new Button("random");
  
  public QuoteButtons(final QuoteController quoteController){
    this.setStyleName("webfortune-QuoteButtons");
    this.random.addClickListener(new ClickListener(){

      public void onClick(Widget arg) {
        quote.random();
        quoteController.load(quote);
      }
    });
    this.next.addClickListener(new ClickListener(){

      public void onClick(Widget arg) {
        quote.next();
        quoteController.load(quote);
      }
    });
    this.previous.addClickListener(new ClickListener(){

      public void onClick(Widget arg) {
        quote.previous();
        quoteController.load(quote);
      }
    });
    add(previous);
    add(random);
    add(next);
  }
  
  void setQuote(Quote quote){
    this.quote = quote;
    setVisible(this.quote != null);
  }
}